import $http from "@/services";
import { message } from "antd"
export default {
    state: {
        attendanceLists: [],
        attendanceTotal: 0,
        attendanceDetail: null,
        attendanceSearch: {
            page: 1,
            size: 5,
            queryData: {}
        }
    },
    // 赋值
    reducers: {
        setAttendanceLists(state, { payload }) {
            return { ...state, attendanceLists: payload }
        },
        setAttendanceTotal(state, { payload }) {
            return { ...state, attendanceTotal: payload }

        },
        setAttendanceDetail(state, { payload }) {
            return { ...state, attendanceDetail: payload }
        },
        setAttendanceSearch(state, { payload }) {
            return { ...state, attendanceSearch: { ...state.attendanceSearch, ...payload } };
        }
    },
    effects: {
        // 初始化数据，获取数据
        *initAttendanceContent({ payload }, { put, call, select }) {
            // 重新处理请求关系
            yield put({
                type: "setAttendanceSearch",
                payload
            })
            const { attendanceSearch } = yield select(state => state.attendanceInfo);
            //请求数据
            const { data, msg } = yield call($http.getAttendance, attendanceSearch);
            yield put({
                type: "setAttendanceLists",
                payload: data.attendanceList
            })
            yield put({
                type: "setAttendanceTotal",
                payload: data.total
            })

        },
        // 重新获取职级详情
        *getDetailAttendance({ payload }, { put, call }) {
            const { data, msg } = yield call($http.getAttendanceDetail, payload);
            if (data) {
                yield put({
                    type: "setAttendanceDetail",
                    payload: data
                })
                yield put({
                    type: "common/setIsShowDetail",
                    payload: true
                });
            } else {
                message.error(msg);
            }

        }
    }
}